//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ruoyi.live.exam.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.live.configuration.SessionInfo;
import com.ruoyi.live.base.domain.LiveTaskUser;
import com.ruoyi.live.base.mapper.LiveTaskUserMapper;
import com.ruoyi.live.tool.commons.ICommons;
import com.ruoyi.live.tool.commons.IConvert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LiveTaskUserService {
    private static final Logger log = LoggerFactory.getLogger(LiveTaskUserService.class);
    @Autowired
    LiveTaskUserMapper dao;

    public LiveTaskUserService() {
    }

    public void addLiveTaskUser(LiveTaskUser entity) throws Exception {
        try {
            entity.setCreateTime(System.currentTimeMillis());
            entity.setCreateUser(SessionInfo.getUserId());
            entity.setState(1);
            this.dao.insert(entity);
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("新增LiveTaskUser失败,编号LiveTaskUserService-addLiveTaskUser-1");
            throw new Exception("新增失败,编号LiveTaskUserService-addLiveTaskUser-1");
        }
    }

    public void updateLiveTaskUser(LiveTaskUser entity) throws Exception {
        try {
            this.dao.updateById(entity);
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("更新LiveTaskUser失败,编号LiveTaskUserService-updateLiveTaskUser-1,id:{}", entity.getId());
            throw new Exception("更新失败,编号LiveTaskUserService-updateLiveTaskUser-1");
        }
    }

    public LiveTaskUser getLiveTaskUser(Long id) {
        return (LiveTaskUser)this.dao.selectById(id);
    }

    public int deleteLiveTaskUser(String[] ids) throws Exception {
        if (ids.length == 0) {
            throw new Exception("请选择要删除的数据,编号LiveTaskUserService-deleteLiveTaskUser-1");
        } else {
            try {
                int count = 0;

                for(int i = 0; i < ids.length; ++i) {
                    if (!ICommons.isNullOrEmpty(ids[i])) {
                        count += this.dao.deleteById(IConvert.string2long(ids[i]));
                    }
                }

                return count;
            } catch (Exception var4) {
                var4.printStackTrace();
                log.error("删除LiveTaskUser失败,编号LiveTaskUserService-deleteLiveTaskUser-2,ids:{}", ids.toString());
                throw new Exception("删除的数据失败,编号LiveTaskUserService-deleteLiveTaskUser-2");
            }
        }
    }

    public List<LiveTaskUser> query(LiveTaskUser entity) {
        QueryWrapper<LiveTaskUser> wrapper = (QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)((QueryWrapper)(new QueryWrapper()).eq(!ICommons.isNullOrEmpty(entity.getId()), "id", entity.getId())).eq(!ICommons.isNullOrEmpty(entity.getState()), "state", entity.getState())).eq(!ICommons.isNullOrEmpty(entity.getCreateUser()), "create_user", entity.getCreateUser())).eq(!ICommons.isNullOrEmpty(entity.getCreateTime()), "create_time", entity.getCreateTime())).eq(!ICommons.isNullOrEmpty(entity.getTaskId()), "task_id", entity.getTaskId())).eq(!ICommons.isNullOrEmpty(entity.getProductId()), "product_id", entity.getProductId())).eq(!ICommons.isNullOrEmpty(entity.getExamId()), "exam_id", entity.getExamId())).eq(!ICommons.isNullOrEmpty(entity.getTaskDuration()), "task_duration", entity.getTaskDuration())).eq(!ICommons.isNullOrEmpty(entity.getTaskType()), "task_type", entity.getTaskType())).eq(!ICommons.isNullOrEmpty(entity.getTaskProgress()), "task_progress", entity.getTaskProgress())).eq(!ICommons.isNullOrEmpty(entity.getTaskProcudtCount()), "task_procudt_count", entity.getTaskProcudtCount())).eq(!ICommons.isNullOrEmpty(entity.getTaskProcudtCountUsed()), "task_procudt_count_used", entity.getTaskProcudtCountUsed())).eq(!ICommons.isNullOrEmpty(entity.getTaskOrder()), "task_order", entity.getTaskOrder())).eq(!ICommons.isNullOrEmpty(entity.getLeuId()), "leu_id", entity.getLeuId());
        return this.dao.selectList(wrapper);
    }

    public void addCount(Long id) {
        this.dao.updateById((new LiveTaskUser()).setId(id).setTaskProcudtCount(((LiveTaskUser)this.dao.selectById(id)).getTaskProcudtCount() + 1));
    }

    public void addCountBatch(String ids, Integer count) {
        String[] idsStr = ids.split(",");
        String[] var4 = idsStr;
        int var5 = idsStr.length;

        for(int var6 = 0; var6 < var5; ++var6) {
            String idStr = var4[var6];
            Long id = IConvert.string2long(idStr);
            this.dao.updateById((new LiveTaskUser()).setId(id).setTaskProcudtCount(((LiveTaskUser)this.dao.selectById(id)).getTaskProcudtCount() + count));
        }

    }
}
